package com.yungu.swift.socket.communication.server.handler.strategy;

import com.yungu.swift.socket.communication.message.base.MessageType;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static com.yungu.swift.socket.communication.message.base.MessageType.*;

/**
 * 策略上下文
 *
 * @author : cuixiuyin
 * @date : 2019/8/30
 */
@Slf4j
public class MessageHandlerContext {

    private static Map<MessageType, MessageHandler> MAP = new ConcurrentHashMap<>(16);

    /**
     * 持有所有策略对象
     */
    static {
        MAP.put(NEW_JOIN_ORDER_ADMIN_NOTIFY, new JoinOrderNotifyHandler());
        MAP.put(NEW_JOIN_ORDER_CALL, new JoinOrderCallHandler());
        MAP.put(LOGIN, new LoginHandler());
        MAP.put(HEART_BEAT, new HeartBeatHandler());
        MAP.put(PUSH_RESPONSE, new PushHandler());
        MAP.put(UPLOAD_LOCATION, new UploadLocationHandler());
        MAP.put(GET_LOCATION, new DriverLocationHandler());
        MAP.put(GET_LOCATION_ORDER, new DriverOrderLocationHandler());
        MAP.put(UPLOAD_LOCATION_JOSN, new BatchUploadLocationHandler());
        MAP.put(ADMIN_USER_LOGIN, new AdminUserLoginHandler());
    }


    public static void handler(ChannelHandlerContext channelHandlerContext, String text, MessageType messageType) {
        log.info("处理报文开始，messageType：{}", messageType.name());
        MAP.get(messageType).handler(channelHandlerContext, text);
        log.info("处理报文结束，messageType：{}", messageType.name());
    }

}
